package com.bwie.controller;

import com.bwie.pojo.TbVote;
import com.bwie.service.VoteService;
import com.bwie.utils.R;
import com.bwie.vo.PageVo;
import freemarker.template.TemplateException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;

/**
 * @Title:
 * @BelongProjecet zk2
 * @BelongPackage com.bwie.controller
 * @Description:
 * @Copyright 研发一部
 * @Author: Mr.yan
 * @Date: 2024/6/4 8:52
 * @Version V1.0
 */
@RestController
@RequestMapping(value = "/vote/vote")
public class VoteController {

    @Autowired
    private VoteService voteService;

    /**
     * @Description: //报名投票（添加信息）
     * @Auther: yanxingru
     * @Date: 2024/6/4 8:56
     * @param:
     * @param tbVote
     * @return com.bwie.utils.R
     */
    @PostMapping("/addVoter")
    public R addVoter(
            @RequestBody TbVote tbVote
            ){
        return voteService.addVoter(tbVote);
    }

    /**
     * @Description: //参选人信息
     * @Auther: yanxingru
     * @Date: 2024/6/4 9:42
     * @param:
     * @return com.bwie.utils.R
     */
    @PostMapping("/voteList")
    public R voteList(
            @RequestBody PageVo pageVo
            ){
        return voteService.voteList(pageVo);
    }

    @PostMapping("/findByVote/{id}")
    public R findByVote(
            @PathVariable Integer id,
            @RequestHeader(name = "token")String token
    ) throws TemplateException, IOException {
        return voteService.findByVote(id,token);
    }

    @PostMapping("/addRecord/{id}/{token}")
    public R addRecord(
            @PathVariable Integer id,
            @PathVariable(name = "token")String token
    ){
        return voteService.addRecords(id,token);
    }

}
